<template>
  <div class="info-item">
    <div class="info-item-key">{{ props.info.key }}：</div>
    <div class="info-item-value">
      <div class="info-item-value-count" :style="{width: `${props.info.count.count / max * maxlenth}px`, backgroundColor: countColor()}"></div>
      <div class="info-item-value-max" :style="{left: `${props.info.count.max/ max * maxlenth}px`}"></div>
      <div class="info-item-value-num">
        {{props.info.count.count}}/{{ props.info.count.max}}
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { Count } from '@renderer/stores/countStore'
import { defineProps } from 'vue'

const props = defineProps<{
  info: {
    key: string
    count: Count
  },
  max: number
}>()

// 最大长度
const maxlenth = 550

// 获取props.info.count.count 或 props.info.count.max 或 props.max 中的最大值
const max = Math.max(props.info.count.count, props.info.count.max, props.max)

// 颜色列表
const colors = [
  '#fe5506',
  '#d5c301',
  '#66e03f',
  '#06e298',
  '#02dbda'
]

// 返回颜色
const countColor = ():string => {
  if(props.info.count.count / props.info.count.max < 0.5) return colors[0]
  if(props.info.count.count / props.info.count.max < 0.8) return colors[1]
  if(props.info.count.count / props.info.count.max < 1.2) return colors[2]
  if(props.info.count.count / props.info.count.max < 1.5) return colors[3]
  return colors[4]
}

</script>

<style lang="scss" scoped>
.info-item {
  width: 100%;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  .info-item-key {
    width: 110px;
    height: 30px;
    line-height: 30px;
    margin-left: 20px;
    border-right: 1px solid #ccc;
  }
  .info-item-value {
    height: 30px;
    width: 100%;
    display: flex;
    align-items: center;
    position: relative;
    .info-item-value-count {
      height: 24px;
      margin-top: 3px;
      margin-bottom: 3px;
    }
    .info-item-value-max {
      position: absolute;
      height: 30px;
      width: 30px;
      border-left: 2px dashed rgb(255, 44, 79);
    }
    .info-item-value-num {
      height: 30px;
      line-height: 30px;
      width: 80px;
      margin-left: 10px;
    }
  }
}
</style>
